package com.appwoo.txtws.service;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import com.appwoo.txtws.component.Global;
import java.io.File;

public class SystemSetWallpaperReceiver extends BroadcastReceiver
{
  int height = 0;
  int width = 0;

  private void getAppropriateSize(Context paramContext, Bitmap paramBitmap)
  {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((WindowManager)paramContext.getSystemService("window")).getDefaultDisplay().getMetrics(localDisplayMetrics);
    int i = localDisplayMetrics.widthPixels;
    int j = localDisplayMetrics.heightPixels;
    int k = paramBitmap.getWidth();
    int m = paramBitmap.getHeight();
    int n = (int)(i / j * m);
    if (n <= k)
    {
      this.width = n;
      this.height = m;
      return;
    }
    int i1 = (int)(j / i * k);
    this.width = k;
    this.height = i1;
  }

  // ERROR //
  private void saveDrawableToCache(Context paramContext, int paramInt, Bitmap paramBitmap, String paramString1, String paramString2)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore 6
    //   3: iload_2
    //   4: iconst_1
    //   5: if_icmpne +46 -> 51
    //   8: aload_1
    //   9: aload 5
    //   11: iconst_0
    //   12: invokevirtual 63	android/content/Context:openFileOutput	(Ljava/lang/String;I)Ljava/io/FileOutputStream;
    //   15: astore 6
    //   17: aload_3
    //   18: getstatic 69	android/graphics/Bitmap$CompressFormat:PNG	Landroid/graphics/Bitmap$CompressFormat;
    //   21: bipush 100
    //   23: aload 6
    //   25: invokevirtual 73	android/graphics/Bitmap:compress	(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z
    //   28: pop
    //   29: aload_3
    //   30: invokevirtual 76	android/graphics/Bitmap:recycle	()V
    //   33: aload_0
    //   34: aload 4
    //   36: aload_1
    //   37: invokespecial 80	com/appwoo/txtws/service/SystemSetWallpaperReceiver:writeToSP	(Ljava/lang/String;Landroid/content/Context;)V
    //   40: aload 6
    //   42: ifnull +8 -> 50
    //   45: aload 6
    //   47: invokevirtual 85	java/io/FileOutputStream:close	()V
    //   50: return
    //   51: new 82	java/io/FileOutputStream
    //   54: dup
    //   55: new 87	java/io/File
    //   58: dup
    //   59: aload 4
    //   61: invokespecial 90	java/io/File:<init>	(Ljava/lang/String;)V
    //   64: invokespecial 93	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   67: astore 7
    //   69: aload 7
    //   71: astore 6
    //   73: goto -56 -> 17
    //   76: astore 10
    //   78: ldc 95
    //   80: aload 10
    //   82: invokevirtual 99	java/io/IOException:getMessage	()Ljava/lang/String;
    //   85: invokestatic 105	com/appwoo/txtws/component/Logger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   88: aload 10
    //   90: invokevirtual 108	java/io/IOException:printStackTrace	()V
    //   93: aload 6
    //   95: ifnull -45 -> 50
    //   98: aload 6
    //   100: invokevirtual 85	java/io/FileOutputStream:close	()V
    //   103: return
    //   104: astore 11
    //   106: aload 11
    //   108: invokevirtual 108	java/io/IOException:printStackTrace	()V
    //   111: return
    //   112: astore 8
    //   114: aload 6
    //   116: ifnull +8 -> 124
    //   119: aload 6
    //   121: invokevirtual 85	java/io/FileOutputStream:close	()V
    //   124: aload 8
    //   126: athrow
    //   127: astore 9
    //   129: aload 9
    //   131: invokevirtual 108	java/io/IOException:printStackTrace	()V
    //   134: goto -10 -> 124
    //   137: astore 13
    //   139: aload 13
    //   141: invokevirtual 108	java/io/IOException:printStackTrace	()V
    //   144: return
    //
    // Exception table:
    //   from	to	target	type
    //   8	17	76	java/io/IOException
    //   17	40	76	java/io/IOException
    //   51	69	76	java/io/IOException
    //   98	103	104	java/io/IOException
    //   8	17	112	finally
    //   17	40	112	finally
    //   51	69	112	finally
    //   78	93	112	finally
    //   119	124	127	java/io/IOException
    //   45	50	137	java/io/IOException
  }

  private void writeToSP(String paramString, Context paramContext)
  {
    SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("wallpaper", 0);
    String str = localSharedPreferences.getString("wallpaperValue", null);
    if ((str != null) && (!"".equals(str)))
    {
      File localFile = new File(str);
      if ((localFile != null) && (localFile.exists()))
        localFile.delete();
    }
    SharedPreferences.Editor localEditor = localSharedPreferences.edit();
    localEditor.putString("wallpaperType", "phoneAlbum");
    localEditor.putString("wallpaperValue", paramString);
    localEditor.commit();
  }

  public void onReceive(Context paramContext, Intent paramIntent)
  {
    if (Global.isAppChangeWallpaper)
      Global.isAppChangeWallpaper = false;
    label283: 
    while (true)
    {
      return;
      int i = -1;
      String str1;
      String str2;
      if ((Global.isSDCard()) && (Global.getSDCardSize(paramContext) >= 30))
      {
        i = 0;
        str1 = "app_bg" + System.currentTimeMillis() + ".png";
        str2 = "";
        if (i != 0)
          break label228;
        File localFile = new File(Environment.getExternalStorageDirectory(), "tylw");
        if ((localFile != null) && (!localFile.exists()))
          localFile.mkdirs();
        str2 = localFile.getAbsolutePath() + File.separator + str1;
      }
      while (true)
      {
        if ((str2 == null) || ("".equals(str2)))
          break label283;
        Bitmap localBitmap1 = ((BitmapDrawable)paramContext.getWallpaper()).getBitmap();
        getAppropriateSize(paramContext, localBitmap1);
        if ((this.width > 0) && (this.height > 0))
        {
          Bitmap localBitmap2 = Bitmap.createBitmap(localBitmap1, 0, 0, this.width, this.height);
          saveDrawableToCache(paramContext, i, localBitmap2, str2, str1);
          localBitmap2.recycle();
        }
        localBitmap1.recycle();
        return;
        if (Global.getMemorySize() < 30)
          break;
        i = 1;
        break;
        label228: if (i == 1)
          str2 = paramContext.getFilesDir().getParent() + File.separator + paramContext.getFilesDir().getName() + File.separator + str1;
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.service.SystemSetWallpaperReceiver
 * JD-Core Version:    0.6.2
 */